package com.easy.common.dao;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import org.apache.commons.dbutils.QueryRunner;
import org.springframework.stereotype.Component;

@Component
public class DBUtilsHelper {

	private DataSource ds = null;  
    private QueryRunner runner = null;  
  
    public DBUtilsHelper() {  
        try {  
            this.ds = DbPoolConnection.getInstance().getDataSource();  
        } catch (SQLException e) {  
            e.printStackTrace();  
        }  
        if (this.ds != null) {  
            this.runner = new QueryRunner(this.ds);  
        }  
    }  
  
    public DBUtilsHelper(DataSource ds) {  
        this.ds = ds;  
        this.runner = new QueryRunner(this.ds);  
    }  
  
    public QueryRunner getRunner() {  
        return this.runner;  
    }  
    
    public String getDataBase() {
    	String database = null ;
    	try {
			Connection conn = this.ds.getConnection() ;
			database = conn.getCatalog() ;
			conn.close() ;
			return database ;
		} catch (SQLException e) {
			e.printStackTrace();
		}
    	return null ;
    }
    
    public static void main(String[] args) {
    	DBUtilsHelper d = new DBUtilsHelper() ;
    	System.out.println(d.getDataBase());
	}
}
